#include"UnitFM.h"

#include"Field.h"
#include"Map.h"

#include<stdio.h>

#include<QMap>

UnitFM::UnitFM(Map *map, UnitAge age, Team team):Unit(map, team, _getFullName(age), "FM", age){
	_initStats(age);
	m_hasRetaliated = false;
}

UnitFM::~UnitFM(){
	
}

//TODO: This could probably use some tweaking.
///Regardless, this should suffice for now.
double UnitFM::getAttackPriority(const Unit *unit)const{
	double priority = 0;
	priority += (10 - unit->health());
	if(unit->type() == TYPE_SR)
		priority += 10;
	else if(unit->type() == TYPE_LR)
		priority += 7;
	else if(unit->type() != TYPE_LM)
		priority += 5;
	priority += unit->attack(true)/100.0;
	priority -= unit->defense(true)/100.0;
	return priority;
}

QString UnitFM::_getFullName(UnitAge age){
	switch(age){
		case AGE_BRZ:
			return "Horseman";
		case AGE_IRN:
			return "Mounted Warrior";
		case AGE_EMA:
			return "Heavy Cavalry";
		case AGE_HMA:
			return "Knight";
		case AGE_LMA:
			return "Heavy Knight";
		case AGE_CA:
			return "Dragoon";
		case AGE_IA:
			return "Lancer";
		default:
			return "Horseman";
	}
}

void UnitFM::_initStats(UnitAge age){
	switch(age){
		case AGE_BRZ:
			m_attack = 6;
			m_defense = 5;
			m_range = 1;
			m_speed = 22;
			m_attackBonusSR = 3;
			m_defenseBonusSR = 3;
			break;
		case AGE_IRN:
			m_attack = 10;
			m_defense = 7;
			m_range = 1;
			m_speed = 22;
			m_attackBonusSR = 4;
			m_defenseBonusSR = 4;
			break;
		case AGE_EMA:
			m_attack = 12;
			m_defense = 13;
			m_range = 1;
			m_speed = 22;
			m_attackBonusSR = 5;
			m_defenseBonusSR = 5;
			break;
		case AGE_HMA:
			m_attack = 15;
			m_defense = 16;
			m_range = 1;
			m_speed = 22;
			m_attackBonusSR = 6;
			m_defenseBonusSR = 6;
			break;
		case AGE_LMA:
			m_attack = 21;
			m_defense = 24;
			m_range = 1;
			m_speed = 24;
			m_attackBonusSR = 7;
			m_defenseBonusSR = 7;
			break;
		case AGE_CA:
			m_attack = 28;
			m_defense = 40;
			m_range = 1;
			m_speed = 24;
			m_attackBonusSR = 10;
			m_defenseBonusSR = 10;
			break;
		case AGE_IA:
			m_attack = 40;
			m_defense = 40;
			m_range = 1;
			m_speed = 24;
			m_attackBonusSR = 15;
			m_defenseBonusSR = 15;
			break;
	}
}

int UnitFM::defenseBonusAgainst(UnitType type)const{
	if(type == TYPE_SR)
		return m_defenseBonusSR;
	return 0;
}

int UnitFM::attackBonusAgainst(UnitType type)const{
	if(type == TYPE_SR)
		return m_attackBonusSR;
	return 0;
}

/*	switch(age){
		case AGE_BRZ:
			break;
		case AGE_IRN:
			break;
		case AGE_EMA:
			break;
		case AGE_HMA:
			break;
		case AGE_LMA:
			break;
		case AGE_CA:
			break;
		case AGE_IA:
			break;
		default:
			break;
	}*/ 
